<style type="text/css">

#mainDiv{
	margin: 0 auto;
	width: 600px;		
}

div.krotka{
	width:600px;
	display:table;
	padding:5px;
}

div.text{
	text-align:center;
	width:100px;
	float:left;	
}

div.input{
	width:500px;
	float:right;
}


</style>

<?php
	if($_POST['kto'] != "" && ($_POST['tel'] != ""  || $_POST['mail']) )
	{
		$conection = mysql_connect($mysql_host,$mysql_user,$mysql_password);
		mysql_set_charset('utf8',$conection);
		@mysql_select_db($mysql_database) or die("Nie udało sie wybrac bazy danych");
		$kto = $_POST['kto'];
		$mail = $_POST['mail'];
		$tel = $_POST['tel'];
		$text = $_POST['text'];
		$id = $_POST['id'];
		
		$query = 'UPDATE `INFO` SET `KTO` = "'.$kto.'" , `EMAIL` = "'.$mail.'" , `TEL` = "'.$tel.'" , `TEXT` = "'.$text.'" WHERE `ID` = "'.$id."\"";

		$result = mysql_query($query);
		if(mysql_error())
			die(mysql_error());
		echo "<div style=\"text-align:center; font-size:30px;\">Zapisano pomyślnie</div>";
	}
	else
	{
			$conection = mysql_connect($mysql_host,$mysql_user,$mysql_password);
			mysql_set_charset('utf8',$conection);
			@mysql_select_db($mysql_database) or die("Nie udało sie wybrac bazy danych");
			$query = "SELECT * FROM `INFO`";

			$result = mysql_query($query);
			if(mysql_error())
				die(mysql_error());
				
			$row = mysql_num_rows($result);
			
			if($row == 1)
			{
				$row = mysql_fetch_assoc($result);
				formularz($row['ID'],$row['KTO'],$row['EMAIL'],$row['TEL'],$row['TEXT']);
			}
			else
			 die("Bład w bazie danych, nie może być wiecej niż 1 wiersz.");
			mysql_close();	
	}
	
	function formularz($id,$kto,$mail,$tel,$text)
	{
		echo 	"<h2 style=\"text-align:center\">Edycja kontatku</h2>
			<form method=\"post\">
			<input type=\"hidden\" value=\"".$id."\" name=\"id\" />
			<div id=\"mainDiv\">
				<div class=\"krotka\">
					<div class=\"text\"><strong>Kto</strong></div>
    				<div class=\"input\"><input type=\"text\" name=\"kto\" value=\"".$kto."\" style=\"width:400px;\"></div>
				</div>
				<div class=\"krotka\">
					<div class=\"text\"><strong>Mail</strong></div>
    				<div class=\"input\"><input type=\"text\" name=\"mail\" value=\"".$mail."\" style=\"width:400px;\"></div>
				</div>
				<div class=\"krotka\">
					<div class=\"text\"><strong>Telefon</strong></div>
    				<div class=\"input\"><input type=\"text\" name=\"tel\" value=\"".$tel."\" style=\"width:400px;\"></div>
				</div>
				<div class=\"krotka\">
    				<div class=\"text\"><strong>Treść</strong></div>
    				<div class=\"input\"><textarea name=\"text\" style=\"width:400px;height:250px;\">".$text."</textarea></div>
				</div>
				<div class=\"krotka\">
    				<input style=\"width:100px; margin: 0 auto; display: block;\" type=\"submit\" value=\"Zapisz\" />
				</div>
			</form>
			</div>";
	}
?>


